﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PBOffice.Models;
namespace PBOffice.DAL
{
    public class UserDeskFunService
    {
        public string GetOrderByUserId(string userId)
        {
            string sql = string.Format("select FunOrders from UserDeskFun where UserId='{0}'", userId);
            string funOrder = null;
            using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, CommandType.Text, sql))
            {
                while (dr.Read())
                {
                    UserDeskFun use = new UserDeskFun();
                    funOrder = dr["FunOrders"].ToString();
                }
            }
            return funOrder;
        }
        public void UpdateUserDeskFun(UserDeskFun user)
        {
            string sql = "update [UserDeskFun] set FunOrders=@FunOrders where UserId=@UserId";
            SqlParameter[] spa = {
                                    new SqlParameter("@UserId",user.UserId),
                                    new SqlParameter("@FunOrders",user.FunOrders)
                                 };
            SqlHelp.ExecuteNonQuery(SqlHelp.connectionstring, CommandType.Text, sql, spa);
        }
        public void AddUserDeskFun(UserDeskFun user)
        {
            string sql = "insert [UserDeskFun] (FunOrders,UserId) values(@FunOrders,@UserId)";
            SqlParameter[] spa = {
                                    new SqlParameter("@UserId",user.UserId),
                                    new SqlParameter("@FunOrders",user.FunOrders)
                                 };
            SqlHelp.ExecuteNonQuery(SqlHelp.connectionstring, CommandType.Text, sql, spa);
        }
        public void DeleteUserDeskFun(string userId)
        {
            string sql = string.Format("delete [UserDeskFun] where UserId='{0}'", userId);
            SqlHelp.ExecuteNonQuery(SqlHelp.connectionstring, CommandType.Text, sql);
        }
    }
}
